﻿using System;
using System.Windows.Forms;
using System.Xml;

namespace 物流管理系统
{
    public partial class Loginform : Form
    {
        public Loginform()
        {
            InitializeComponent();
        }

        private void login_Click(object sender, EventArgs e)
        {
            ReMatch re = new ReMatch();
            DBOperation dboperation = new DBOperation();
            /*Functionform functionform = new Functionform();
            Hide();
            functionform.ShowDialog();
            Close();*/
            if (loginusernametext.Text=="")
            {
                MessageBox.Show("用户名不能为空！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (loginpasswordtext.Text=="")
            {
                MessageBox.Show("密码不能为空！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                if (re.specialmatch(loginusernametext.Text)||re.specialmatch(loginpasswordtext.Text))
                {
                    MessageBox.Show("输入非法！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                switch (dboperation.login(loginusernametext.Text, loginpasswordtext.Text))
                {
                    case 0:
                        {
                            Functionform functionform = new Functionform();
                            functionform.idlabel.Text=loginusernametext.Text;
                            functionform.setpowerlist(loginusernametext.Text);
                            Hide();
                            functionform.ShowDialog();
                            Close();
                            break;
                        }
                    case 1:
                        {
                            MessageBox.Show("密码错误！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loginpasswordtext.Clear();
                            return;
                        }
                    case 2:
                        {
                            MessageBox.Show("用户名不存在！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            loginusernametext.Clear();
                            loginpasswordtext.Clear();
                            return;
                        }
                    case 3:
                        {
                            MessageBox.Show("连接超时，请检查网络设置！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                }

            }
        }



        private void quit_Click(object sender, EventArgs e) => Close();

        private void 登录界面_Load(object sender, EventArgs e) => loginpasswordtext.PasswordChar='❤';
    }
}
